package com.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.entity.Response;
import com.entity.pojo.WrUser;
import com.entity.vo.LoginResult;
import com.service.UserService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.Resources;
import java.util.Map;

@RestController
public class LoginController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    public Response userLogin(@RequestBody WrUser user) {
        LoginResult result = userService.userLogin(user);;
        if (result != null) {
            return new Response().setSuccess().appendMsg("user", result.getUser())
                    .appendMsg("token", result.getToken());
        } else {
            return new Response().setFailed().setErrMsg("用户名或密码错误");
        }
    }
}
